# 使用一个Python 字典存储数据，并将它转换成XML 格式

from xml.etree.ElementTree import Element, tostring

def dict_to_xml(tag, d):
    elem = Element(tag)
    # 设置属性
    elem.set('_id', '1234')
    for key, value in d.items():
        child = Element(key)
        child.text = str(value)
        elem.append(child)
    return elem

s = { 'name': 'GOOG', 'shares': 100, 'price':490.1 }
e = dict_to_xml('stock', s)
print(tostring(e))
